package org.cardoso.persistence;

import java.util.List;

import javax.ejb.Stateless;
import javax.ejb.TransactionManagement;
import javax.ejb.TransactionManagementType;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.cardoso.persistence.filter.QueryFilter;

@Stateless
@TransactionManagement(TransactionManagementType.CONTAINER)
public class PersistenceEJB<T> implements Persistence<T> {

	@PersistenceContext
	protected EntityManager entityManager;
	
	@Override
	public void save(T entity) {
		this.entityManager.merge(entity);
	}

	@Override
	public void setEntityManager(EntityManager entityManager) {
		this.entityManager = entityManager;
	}

	@Override
	public void remove(T entity) {
		this.entityManager.remove(entity);
	}

	@Override
	public T getEntity(Long id) {
		// TODO Auto-generated method stub
		return null;
	}

	@SuppressWarnings({ "unchecked", "rawtypes" })
	@Override
	public T getEntity(Class entityClass, Long id) {
		return (T) this.entityManager.find(entityClass, id);
	}

	@Override
	public Long count() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<T> find() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Long count(QueryFilter queryFilter) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<T> find(QueryFilter queryFilter) {
		// TODO Auto-generated method stub
		return null;
	}
	
}